import * as utils from '../utils'

function createCourse13 (gl: WebGLRenderingContext) {
  gl.clearColor(0.0, 0.0, 0.0, 1.0)
  gl.clear(gl.COLOR_BUFFER_BIT)

  const vectexShaderSrc = `
  attribute vec4 a_Position;
  attribute float a_PointSize;
    void main() {
      gl_Position = a_Position;
      gl_PointSize = a_PointSize;
    }
  `

  const fragmentShaderSrc = `
  precision mediump float;
  uniform vec4 u_FragColor;
    void main() {
        gl_FragColor = u_FragColor;
    }
  `
  const program = utils.initShaders(gl, vectexShaderSrc, fragmentShaderSrc)

  const aPosition = gl.getAttribLocation(program, 'a_Position')
  const aPointSize = gl.getAttribLocation(program, 'a_PointSize')

  const vertics = new Float32Array([
    0.0, 0.5, -0.5, -0.5, 0.5, -0.5
  ])

  const pointSizes = new Float32Array([
    5.0, 10.0, 15.0
  ])

  const vertexBuffer = gl.createBuffer()
  gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer)
  gl.bufferData(gl.ARRAY_BUFFER, vertics, gl.STATIC_DRAW)
  gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0)
  gl.enableVertexAttribArray(aPosition)

  const pointSizeBuffer = gl.createBuffer()
  gl.bindBuffer(gl.ARRAY_BUFFER, pointSizeBuffer)
  gl.bufferData(gl.ARRAY_BUFFER, pointSizes, gl.STATIC_DRAW)
  gl.vertexAttribPointer(aPointSize, 1, gl.FLOAT, false, 0, 0)
  gl.enableVertexAttribArray(aPointSize)

  gl.drawArrays(gl.POINTS, 0, 3)
}

export {
  createCourse13
}
